package com.fenqile.pop.enums;

import java.util.Objects;

import com.fenqile.pop.utility.TypeToken;

/**
 * 自定义名称的枚举类型
 * 
 * @author Coby [cobylin@live.com] 2017
 */
public interface NamedEnum<T extends Enum<T>> {
	
	String getName();
	
	@SuppressWarnings("unchecked")
	default T of(String name) {
		Class<T> tClass = new TypeToken<T>(){}.getGenericClass();
		T[] vs = tClass.getEnumConstants();
		for (T t : vs) {
			if (Objects.equals(((NamedEnum<T>)t).getName(), name))
				return t;
		}
		return null;
	}
}
